package com.ews.onlineexchange.model;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.PrePersist;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

@Entity
public class RejectRecord extends DataEntity {
	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;

	private String				reason;
	private Date				rejectTime;

	@NotNull
	@Length(max = 2000)
	public String getReason() {
		return reason;
	}

	public void setReason(String reason) {
		this.reason = reason;
	}

	@NotNull
	@Temporal(TemporalType.TIMESTAMP)
	public Date getRejectTime() {
		return rejectTime;
	}

	public void setRejectTime(Date rejectTime) {
		this.rejectTime = rejectTime;
	}
	
	@PrePersist
	public void prePersist() {
		super.prePersist();
		setRejectTime(new Date());
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((reason == null) ? 0 : reason.hashCode());
		result = prime * result + ((rejectTime == null) ? 0 : rejectTime.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		RejectRecord other = (RejectRecord) obj;
		if (reason == null) {
			if (other.reason != null)
				return false;
		} else if (!reason.equals(other.reason))
			return false;
		if (rejectTime == null) {
			if (other.rejectTime != null)
				return false;
		} else if (!rejectTime.equals(other.rejectTime))
			return false;
		return true;
	}
}
